/*
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

package jsr203.nio.file;

import java.io.IOException;
import jsr203.nio.file.attribute.BasicFileAttributes;

/**
 * A visitor of files. An implementation of this interface is provided to the
 * {@link Files#walkFileTree walkFileTree} utility method to visit each file
 * in a tree.
 *
 * @since 1.7
 */

public interface FileVisitor {

    /**
     * Invoked for a directory before entries in the directory are visited.
     *
     * <p> The result from this method determines if entries in the directory
     * are visited. If the result is {@link FileVisitResult#CONTINUE CONTINUE}
     * then the entries are visited. If the result is {@link
     * FileVisitResult#PRUNE PRUNE} then entries in the directory (and any
     * descendants) will not be visited.
     *
     * @param   dir
     *          A reference to the directory
     * @param   relPath
     *          The relative path from the starting file to the directory, or
     *          {@code null} for the starting directory
     *
     * @return  the visit result
     */
    FileVisitResult preVisitDirectory(FileRef dir, Path relPath);

    /**
     * Invoked for a file that is not a directory, and its basic file attributes
     * could be read.
     *
     * @param   file
     *          A reference to the file
     * @param   relPath
     *          The relative path from the starting file to the file, or
     *          {@code null} for the starting file
     * @param   attrs
     *          The file's basic attributes
     *
     * @return  the visit result
     */
    FileVisitResult visitFile(FileRef file, Path relPath, BasicFileAttributes attrs);

    /**
     * Invoked for a directory after entries in the directory, and all of their
     * descendants, have been visited.
     *
     * @param   dir
     *          A reference to the directory
     * @param   relPath
     *          The relative path from the starting file to the directory, or
     *          {@code null} for the starting directory
     *
     * @return  the visit result
     */
    FileVisitResult postVisitDirectory(FileRef dir, Path relPath);

    /**
     * Invoked for a file when its basic file attributes could not be read.
     *
     * @param   file
     *          A reference to the file
     * @param   relPath
     *          The relative path from the starting file to the file, or
     *          {@code null} for the starting file
     * @param   exc
     *          The exception thrown when attempting to read the file
     *          attributes
     *
     * @return  the visit result
     */
    FileVisitResult visitFileFailed(FileRef file, Path relPath, IOException exc);

    /**
     * Invoked for a directory if it cannot be opened, or an I/O error occurs
     * when iterating over the directory.
     *
     * @param   dir
     *          A reference to the directory
     * @param   relPath
     *          The relative path from the starting file to the directory, or
     *          {@code null} for the starting directory
     * @param   exc
     *          The exception thrown when open or iterating
     *
     * @return  the visit result
     */
    FileVisitResult visitDirectoryFailed(FileRef dir, Path relPath, IOException exc);
}
